import os
import shutil
from pathlib import Path

def ensure_directory(path: str) -> str:
    """确保目录存在，如果不存在则创建"""
    Path(path).mkdir(parents=True, exist_ok=True)
    return path

def get_file_size(file_path: str) -> int:
    """获取文件大小（字节）"""
    if not os.path.exists(file_path) or not os.path.isfile(file_path):
        return 0
    return os.path.getsize(file_path)

def delete_file_safely(file_path: str) -> bool:
    """安全删除文件"""
    try:
        if os.path.exists(file_path) and os.path.isfile(file_path):
            os.remove(file_path)
            return True
        return False
    except Exception:
        return False

def delete_directory_safely(dir_path: str) -> bool:
    """安全删除目录"""
    try:
        if os.path.exists(dir_path) and os.path.isdir(dir_path):
            shutil.rmtree(dir_path)
            return True
        return False
    except Exception:
        return False

def copy_directory(src: str, dst: str) -> bool:
    """复制目录"""
    try:
        if os.path.exists(src) and os.path.isdir(src):
            shutil.copytree(src, dst, dirs_exist_ok=True)
            return True
        return False
    except Exception:
        return False
